﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Slb.Ocean.Petrel.Basics;

namespace Public.Ocean.Petrel.Extensions.UnitTest
{
    class SelfObservableEnumeratorFactory : IObservableElementEnumerableFactory
    {
        public IObservableElementEnumerable GetEnumerable(object domainObj)
        {
            return new SelfObservableEnumerator(domainObj);
        }
    }

    class SelfObservableEnumerator : IObservableElementEnumerable
    {
        object parent;
        public SelfObservableEnumerator(object parent)
        {
            this.parent = parent;
        }

        public event EventHandler<ElementEnumerableChangeEventArgs> EnumerableChanged { add { } remove { } }

        static int count = 0;
        public System.Collections.IEnumerator GetEnumerator()
        {
            count++;
            if (count % 2 != 0)
            {
                return new object[] { parent }.GetEnumerator();
            }
            else
            {
                return new object[0].GetEnumerator();
            }
        }
    }
}
